/*
 *  This file is part of "CD to Web Audio 2".
 *
 *  Written by Phillip Hopper
 * 
 *  Copyright 2008, Phillip Hopper, Sibertec Services
 *  www.sibertec.com
 *  philhopper@sibertec.com
 * 
 *  "CD to Web Audio 2" is free software: you can redistribute it and/or
 *  modify it under the terms of the GNU General Public License as
 *  published by the Free Software Foundation, either version 3 of the
 *  License, or (at your option) any later version.
 *
 *  "CD to Web Audio 2" is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License along
 *  with "CD to Web Audio 2".  If not, see <http://www.gnu.org/licenses/
 * 
 *  First release:  2008-03-07, Phillip Hopper
 */

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace CD2WebAudio3UI.Forms
{
    public partial class frmShutdown : Form
    {
        private int m_TimeRemaining = 120;
        private bool m_JustClose = false;
        private string m_Message = "Shutting down in ";


        public bool JustClose
        {
            set
            {
                m_JustClose = true;
                Text = "Closing";
                lblShutdown.Text = "Closing in 2:00";
                m_Message = "Closing in ";
            }
        }

        public frmShutdown()
        {
            InitializeComponent();
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.Close();

        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            try
            {
                m_TimeRemaining--;
                if (m_TimeRemaining >= 0) lblShutdown.Text = m_Message + new DateTime(2000, 1, 1).AddSeconds(m_TimeRemaining).ToString("m:ss");

                if (m_TimeRemaining <= 0)
                {
                    timer1.Enabled = false;
                    try
                    {
                        if (m_JustClose)
                        {
                            Application.Exit();
                        }
                        else
                        {
                            //string path = Environment.GetEnvironmentVariable("windir") + @"\System32\shutdown.exe";
                            System.Diagnostics.Process.Start("shutdown.exe", "-s");
                            Application.Exit();
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.ToString(), TheApp.Title, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    }
                }
            }
            finally { }
        }
    
    }
}